package com.nervenets.utils;

import com.alibaba.fastjson.JSON;
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;

import java.io.IOException;

public final class QQUtils {
    // 短信应用SDK AppID
    private static int appid = 1400179440; // 1400开头
    // 短信应用SDK AppKey
    private static String appkey = "fb329205d26f65bd7d9e4bd3a378367e";

    public static SmsSingleSenderResult sendMobileValidationCode(String mobile, String code) throws HTTPException, IOException {
        SmsSingleSender sender = new SmsSingleSender(appid, appkey);
        String[] params = {code, "5"};
        String smsSign = "";
        return sender.sendWithParam("86", mobile, 271837, params, smsSign, "", "");
        // 签名参数未提供或者为空时，会使用默认签名发送短信
    }

    public static void main(String[] args) throws HTTPException, IOException {
        final SmsSingleSenderResult result = sendMobileValidationCode("13882128901", String.valueOf(NumberUtil.randomNumber(100000, 999999)));
        System.out.println(JSON.toJSONString(result));
    }
}
